package net.chengp.ms.auth.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

/**
 * 用户实体
 * @author chengp
 *
 */
public class UserDetails implements org.springframework.security.core.userdetails.UserDetails {

	private static final long serialVersionUID = -177410811720326297L;
	
	private String username;
	
	private String password;
	
	private Collection<SimpleGrantedAuthority> authorities;
	
	public UserDetails(String username, String password, List<String> roles) {
		this.username = username;
		this.password = password;
		if(roles!=null) {
			authorities = new ArrayList<>();
			roles.forEach(item->{
				authorities.add(new SimpleGrantedAuthority(item));
			});
		}
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return authorities;
	}

	@Override
	public String getPassword() {
		return password;
	}

	@Override
	public String getUsername() {
		return username;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

}
